package com.ys.web.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.ys.extend.common.model.AjaxJson;
import com.ys.web.pojo.IndustryMsgInfo;
import com.ys.web.service.QuadrantService;

/**
 * 四象限
 * @author wdj
 *
 */
@Scope("prototype")
@Controller
@RequestMapping("/quadrantController")
public class QuadrantController {
	
	/**四象限*/
	@Autowired
	private QuadrantService quadrantService;
	
	@RequestMapping(params="showQuadrant")
	public ModelAndView uploadCsv(HttpServletRequest request){
		
		return new ModelAndView("quadrant/quadrantList");
	}	
	
	/**
	 * 根据行业获取对应的四象限
	 * @param industryId
	 * @return 对应的四象限列表
	 */
	@RequestMapping(params="getQuadrantsByIndustryId")
	@ResponseBody
	public List<IndustryMsgInfo> getQuadrantsByIndustryId(String industryId) {
		List<IndustryMsgInfo> list = quadrantService.getQuadrantByIndustryId(industryId);	
		return list;
	}

	/**
	 * 根据公司id获取对应的四象限边界值
	 * @param companyId
	 * @return 对应的四象限列表
	 */
	@RequestMapping(params="getQuadrantsByCompanyId")
	@ResponseBody
	public List<IndustryMsgInfo> getQuadrantsByCompanyId(String companyId) {
		List<IndustryMsgInfo> list = quadrantService.getQuadrantByCompanyId(Integer.parseInt(companyId));	
		return list;
	}
	
	
	
	/**
	 * 批量修改四象限的边界值
	 * @param quadrantInfoList 四象限对象列表
	 */
	@RequestMapping(params="batchUpdateQuadrant")
	@ResponseBody
	public AjaxJson batchUpdateQuadrant(@RequestBody IndustryMsgInfo[] quadrantInfoList) {	
		AjaxJson j = new AjaxJson();
		j.setMsg("修改成功");		
		
		if(quadrantInfoList!= null && quadrantInfoList.length>0) {
			try {
				//执行批量修改
				quadrantService.batchUpdateQuadrantInfo(quadrantInfoList);					
			} catch (Exception e) {				
				j.setSuccess(false);
				j.setMsg("保存失败");
				e.printStackTrace();
			}
		}
		else {			
			j.setSuccess(false);
			j.setMsg("传递的参数为空");
		}
				
		return j;
	}
	
}
